<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Member_model extends CI_Model{
	
	function __construct()
	{
		parent::__construct();
		
	}
	
	function getMember($query=FALSE,$id=FALSE,$limit=FALSE,$offset=FALSE,$nama=FALSE)
	{
		if (!$query):
			$this->db->where('member_id',$id);
			return $this->db->get('tb_member')->row();
		elseif($query=='all'):
			$this->db->limit($limit,$offset);
			$this->db->order_by('member_id','desc');
			return $this->db->get('tb_member')->result_array();
		elseif($query=='cari'):
			$this->db->limit($limit,$offset);
			$this->db->like('nama',$nama);
			$this->db->order_by('member_id','desc');
			return $this->db->get('tb_member')->result_array();
		endif;
	}
	
	function addMember($data)
	{
		$this->db->insert('tb_member',$data);
	}
	
	function editMember($id,$data)
	{
		$this->db->where('member_id',$id);
		$this->db->update('tb_member',$data);
	}
	
	function deleteMember($id)
	{
		$this->db->where('member_id',$id);
		$this->db->delete('tb_member');
	}
	
	function addTempLogin($data)
	{
		$this->db->insert('tb_temp_login',$data);
	}
	
	function deleteTempLogin($session_id)
	{
		$this->db->where('session_id',$session_id);
		$this->db->delete('tb_temp_login');
	}
	
	
	function getDataLogin($session_id,$cust_id)
	{
		$this->db->where('session_id',$session_id);
		$this->db->where('temp_mem_id',$cust_id);
		$this->db->join('tb_member','tb_member.member_id = tb_temp_login.temp_mem_id');
		$this->db->join('tb_kab','tb_kab.kab_id = tb_member.mem_kab_id');
		$this->db->join('tb_province','tb_province.prov_id = tb_member.mem_prov_id');
		$query = $this->db->get('tb_temp_login');
		return $query->row();
	}
	
	
	function get_KabByProv($provId)
	{
		$this->db->where('prov_id',$provId);
		return $this->db->get('tb_kab')->result_array();
	}
}
?>